package com.shujia.flink.tf

import org.apache.flink.api.java.functions.KeySelector
import org.apache.flink.streaming.api.scala._

object Demo5KeyBy {
  def main(args: Array[String]): Unit = {

    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    val studentDS: DataStream[String] = env.readTextFile("data/students.txt")


    val keyByDS: KeyedStream[String, String] = studentDS.keyBy(new KeySelector[String, String] {
      override def getKey(value: String): String = {
        //按照班级进行keyBy
        value.split(",")(4)
      }
    })

    keyByDS.print()


    env.execute()


  }

}
